<?php

require_once('class/nexmo/NexmoMessage.php');

if($_SERVER['REQUEST_METHOD'] == "POST")
{
	if(isset($_POST['txtFrom']) && isset($_POST['txtMessage']))
	{
		$from = $_POST['txtFrom'];
		$to = "61452341110";
		$api_key = "cc847183";
		$api_secret = "a630d18c";
		$message = $_POST['txtMessage'];
		//https://rest.nexmo.com/sms/json?api_key=cc847183&api_secret=a630d18c&from=NEXMO&to=61452341110&text=Welcome+to+Nexmo
		
		$sms = new NexmoMessage($api_key, $api_secret);
		$sms->sendText( $to, $from, $message );
		
		$receipt = new NexmoReceipt();
	    if ($receipt->exists()) {
	         switch ($receipt->status) {
	             case $receipt::STATUS_DELIVERED:
	                 // The message was delivered to the handset!
	             		echo "Message Sent!";
	                 break;
	             
	             case $receipt::STATUS_FAILED:
	             		echo "Message sending failed!";
	             	break;
	             case $receipt::STATUS_EXPIRED:
	                 // The message failed to be delivered
	             		echo "Message failed to deliever!";
	                 break;
	         }
	     }
		
	}
}
else
{
	
?>
<!-- @AUTHOR : NISCHAL SHRESTHA -->
<!-- NEXMO demo message -->
<html>
<head>
<title>Send Message to Nischal</title>
<style>

	#wrapper
	{
		position : relative;
		width : 450px;
		height : 260px;
		margin : 0 auto;
		border-left : 5px solid gray;
		padding-left : 20px;
		background :  #dadada;
	}
	#wrapper > h1
	{
		font-family : Arial;
		font-size : 2em;
		color : #5392d6;
	}
	#message
	{
		width : 200px;
		height : 100px;
	}
</style>
</head>
<body>
	<div id="wrapper">
	<h1>Send a Message to Nischal</h1>
	<form method="POST" action="testingsms.php">
		<table>
		<tr><td>From (NAME) : </td><td><input type="text" name="txtFrom" placeholder="Your name here"></td></tr>
		<tr><td>To (FIXED) : </td><td><input type="text" name="txtTo" value="Nischal (+61452341110)" READONLY></td></tr>
		<tr><td>Message : </td><td><textarea id = "message" name="txtMessage" placeholder="message here.."></textarea></td></tr>
		<tr><td> </td><td><input type="submit" value="send"></td></tr>
		</table>
	</form>
	</div>
</body>
</html>
<?php
}
?>